﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tetris.Interfaces;

namespace Tetris.Graphics
{
    public class Background: IDrawableObject
    {
        private readonly IEnumerable<IDrawableObject> _layers;
        private readonly int _viewportWidth;
        private readonly int _viewportHeight;

        public Background( int viewportHeight, int viewportWidth, IEnumerable<IDrawableObject> layers )
        {
            _viewportHeight = viewportHeight;
            _viewportWidth = viewportWidth;
            _layers = layers;
        }

        public Vector2 Position
        {
            get { return new Vector2( 0, 0 ); }
            set
            {
                throw new InvalidOperationException( "Cant change position of a background layer!" );
            }
        }

        public int Width { get { return _viewportWidth; } }
        public int Height { get { return _viewportHeight; } }
        public bool Active { get { return true; } }

        public void Initialize( IGameManager gameManager )
        {
            foreach( var layer in _layers )
            {
                layer.Initialize( gameManager );
            }
        }

        public void Update( IGameManager gameManager )
        {
            foreach( var layer in _layers )
            {
                layer.Update( gameManager );
            }
        }

        public void Draw( SpriteBatch spriteBatch, IGameManager gameManager, GameTime gameTime )
        {
            foreach( var layer in _layers )
            {
                layer.Draw( spriteBatch, gameManager, gameTime );
            }
        }
    }
}
